package com.tiantianyuegou.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.tiantianyuegou.R;
import com.tiantianyuegou.http.ApiDefine;
import com.tiantianyuegou.model.GoodsModel;
import com.tiantianyuegou.model.ShangJiaModel;
import com.tiantianyuegou.util.ImageLoadeUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 本地商列表
 * Created by George on 2016/9/20.
 */
public class ShangJiaAdapter extends BaseAdapter {

    private Context context;
    private List<ShangJiaModel> data;


    public ShangJiaAdapter(Context context) {
        this.context = context;
        data=new ArrayList<>();
    }

    public ShangJiaAdapter(Context context, List<ShangJiaModel> data) {
        this.context = context;
        this.data = data;
    }
    public void setData(List<ShangJiaModel> data){
        this.data.clear();
        this.data.addAll(data);
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null){
            convertView = View.inflate(context, R.layout.item_list_shangjia, null);
            vh = new ViewHolder();
            vh.iv_store = (ImageView) convertView.findViewById(R.id.iv_store);
            vh.item_coupon_name = (TextView) convertView.findViewById(R.id.item_coupon_name);
            vh.tv_sheng_shi_qu = (TextView) convertView.findViewById(R.id.tv_sheng_shi_qu);
            vh.item_coupon_endDate = (TextView) convertView.findViewById(R.id.item_coupon_endDate);
            convertView.setTag(vh);


        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        ShangJiaModel model = data.get(position);
        ImageLoader.getInstance().displayImage(model.getTbLogo(),vh.iv_store);
        vh.item_coupon_name.setText(model.getTbName());
        vh.tv_sheng_shi_qu.setText(model.getTbPname() + model.getTbCname() + model.getTbOname());
        vh.item_coupon_endDate.setText(model.getTbScore());
        return convertView;
    }

    class ViewHolder{
        ImageView iv_store;
        TextView item_coupon_name,tv_sheng_shi_qu,item_coupon_endDate;

    }
}
